<?php

namespace App\Admin\Forms\User;

use App\Lib\WeApp\WeApp;
use App\Models\User\WxUser;
use App\Wen\Utils\Utils;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class UserShareForm extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        return;
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $new_app = new WeApp();
        $wxlink = $new_app->getWxLink();

        $user_id = $this->payload["user_id"];
        $this->hidden('user_id')->value($user_id);
        $tenant_id = WxUser::where('id', $user_id)->value('tenant_id');

        $this->html(function () {
            return '';
        }, '<b>一、UrlLink</b>');
        $this->html(function () {
            return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">可以在任意移动端的浏览器打开，可直接打开微信小程序的对应分站</div>';
        }, '');
        $this->html(function () use ($user_id,$tenant_id, $wxlink){
            return $wxlink->genWxUrllink('/pages/tabbar/index/index', 'form_user='.$user_id.'&tenant='.$tenant_id);
        }, '');
        $this->html(function () {
            return '';
        }, '<b>一、二维码</b>');
        $this->html(function () use ($tenant_id,$user_id, $wxlink){
            $code_url = Utils::getMiniCode('/pages/tabbar/index/index', 'form_user='.$user_id.'&tenant='.$tenant_id, 0);
            return '<img src="'.$code_url.'" style="width: 120px;height: 120px"/>';
        }, '');
    }

}
